package com.sxyjhh.fg.controller;

import com.sxyjhh.fg.service.CreditSaveDataService;
import com.sxyjhh.fg.service.SaveDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping(value = "/service")
public class ReceiveDataController {

    @Autowired
    private SaveDataService saveDataService;

    @Autowired
    private CreditSaveDataService creditSaveDataService;

    @RequestMapping(value = "/pushData", method = RequestMethod.POST)
    public String saveData(@RequestParam(value = "regPersonType") String regPersonType
            , @RequestParam(value = "dataArray") String dataArray) {
        boolean result = saveDataService.saveData(regPersonType, dataArray);
        return result ? "1" : "0";
    }

    @RequestMapping(value = "/creditPushData", method = RequestMethod.POST)
    public String creditPushData(@RequestParam(value = "ythType") String ythType,
                            @RequestParam(value = "dataArray") String dataArray,
                           @RequestParam(value = "tableName") String tableName) throws ParseException {
        boolean result = creditSaveDataService.saveData(ythType, dataArray, tableName);
        return result ? "1" : "0";
    }
    @RequestMapping(value = "/delData", method = RequestMethod.POST)
    public String delData(@RequestParam(value = "tableName") String tableName) {
        boolean result = creditSaveDataService.delData( tableName);
        return result ? "1" : "0";
    }
}
